#include "RequestDispatcher.h"
#include "RequestHandler.h"
#include "JsonUtil.h"
#include "HandlerFactory.h"

RequestDispatcher::RequestDispatcher()
{
}

void RequestDispatcher::dispatch(TcpSocket *socket, char *content)
{
    map<string,string> paramMap=JsonUtil::strjsonParseMap(content);
    RequestHandler *handler=nullptr;

    int type=atoi(paramMap["type"].c_str());
    if (type==0)
    {
        //检测更新
        //handler=new checkUpdateHandler();
        //handler=checkUpdateHandler::getInstance();
        handler=HandlerFactory::getHandler("check");
        handler->handler(socket,paramMap);
    }else if (type==1)
    {
        //更新
        //handler =new UpdateHandler();
        //handler=checkUpdateHandler::getInstance();
        handler=HandlerFactory::getHandler("updata");
        handler->handler(socket,paramMap);
    }
}

RequestDispatcher::~RequestDispatcher()
{
}
